package com.aaa.service.mht.impl;

import cn.hutool.core.util.ObjectUtil;
import com.aaa.dao.ReturnRecordsDao;
import com.aaa.dao.mht.TestResultMhtDao;
import com.aaa.entity.ReturnRecords;
import com.aaa.entity.mht.TestResultMht;
import com.aaa.entity.system.PageOrder;
import com.aaa.entity.tester.Tester;
import com.aaa.service.mht.TestResultMhtService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author ：肖成杰（1752167034@qq.com）
 * @date ：Created in 2022/9/3 14:45
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class TestResultMhtServicePmpl implements TestResultMhtService {

    @Autowired
    TestResultMhtDao testResultMhtDao;

    @Autowired
    private ReturnRecordsDao returnRecordsDao;

    @Override
    public Page queryAll(PageOrder pageOrder, TestResultMht testResultMht) {
        //拿出pageOrder里面的所有数据
        PageHelper.startPage(pageOrder.getPage(), pageOrder.getLimit());
        //判断数据是否为空
        if (ObjectUtil.isNotEmpty(pageOrder.getField())) {
            PageHelper.orderBy(pageOrder.getFieldOrder());
        }
        //将实体类型转化为Page类
        List<TestResultMht> list = testResultMhtDao.queryAll(testResultMht);

        Page pageResult = (Page) list;
        return pageResult;
    }

    @Override
    public int deleteById(int[] id) {
        testResultMhtDao.delete(id);
        return testResultMhtDao.deleteById(id);
    }

    @Override
    public List<TestResultMht> queryByPhone(Tester tester) {
        return  testResultMhtDao.queryByPhone(tester);
    }

    @Override
    public List<TestResultMht> queryChart(int id) {
        return testResultMhtDao.queryChart(id);
    }

    @Override
    public List<TestResultMht> queryResult(int id, String type) {
        return testResultMhtDao.queryResult(id);
    }

    @Override
    public List<TestResultMht> queryStatement() {
        return testResultMhtDao.queryStatement();
    }

    @Override
    public List<Map<String, Object>> getPlanId() {
        return testResultMhtDao.getPlanId();
    }

    @Override
    public Page<Map<String, Object>> getByTesterId(PageOrder pageOrder, Integer testerId) {
        //拿出pageOrder里面的所有数据
        PageHelper.startPage(pageOrder.getPage(), pageOrder.getLimit());
        //判断数据是否为空
        if (ObjectUtil.isNotEmpty(pageOrder.getField())) {
            PageHelper.orderBy(pageOrder.getFieldOrder());
        }
        return (Page<Map<String,Object>>) testResultMhtDao.getByTesterId(testerId);
    }



    @Override
    public Page<ReturnRecords> getReturnRecords(PageOrder pageOrder,ReturnRecords records) {
        //拿出pageOrder里面的所有数据
        PageHelper.startPage(pageOrder.getPage(), pageOrder.getLimit());
        //判断数据是否为空
        if (ObjectUtil.isNotEmpty(pageOrder.getField())) {
            PageHelper.orderBy(pageOrder.getFieldOrder());
        }
        return (Page<ReturnRecords>) returnRecordsDao.getReturnRecordsMHT(records);
    }

    @Override
    public int insertReturn(ReturnRecords records) {
        return returnRecordsDao.insertMHT(records);
    }

    @Override
    public Integer deleteReturn(int[] id) {
        return returnRecordsDao.deleMHT(id);
    }

    @Override
    public Integer updateReturn(ReturnRecords returnRecords) {
        return returnRecordsDao.updateMHT(returnRecords);
    }


}